package com.cup.jpa.demo.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cup.jpa.demo.model.User;
import com.cup.jpa.demo.server.UserService;

@RestController
@RequestMapping("demo")
public class DemoController {

	@Autowired
	private UserService userService;
	
	@GetMapping(value = "/getall")
	@PreAuthorize("hasRole('ADMIN','CUSTOMER')")
    public List<User> getAll() {
        return userService.getUserlist();
    }
	
	@GetMapping(value = "/get")
	@PreAuthorize("hasRole('ADMIN')")
    public User get(@RequestParam String id) {
        return userService.getUserById(Integer.valueOf(id));
    }
}
